# -*- Mode: makefile-gmake -*-

EXE = test_core_plugins

TEST_PLUGIN_SRC_DIR = .
TEST_PLUGIN1_SRC = test_plugin1.c
TEST_PLUGIN2_SRC = test_plugin2.c
TEST_PLUGIN3_SRC = test_plugin3.c
TEST_PLUGIN4_SRC = test_plugin4.c
TEST_PLUGIN5_SRC = test_plugin5.c
TEST_PLUGIN6_SRC = test_plugin6.c
TEST_PLUGIN7_SRC = test_plugin7.c

TEST_PLUGIN_BUILD_DIR = build
TEST_PLUGIN_DEBUG_BUILD_DIR = $(TEST_PLUGIN_BUILD_DIR)/debug
TEST_PLUGIN_RELEASE_BUILD_DIR = $(TEST_PLUGIN_BUILD_DIR)/release
TEST_PLUGIN_COVERAGE_BUILD_DIR = $(TEST_PLUGIN_BUILD_DIR)/coverage

TEST_PLUGIN1 = test_plugin1.so
TEST_PLUGIN1_DEBUG_LIB = $(TEST_PLUGIN_DEBUG_BUILD_DIR)/$(TEST_PLUGIN1)
TEST_PLUGIN1_RELEASE_LIB = $(TEST_PLUGIN_RELEASE_BUILD_DIR)/$(TEST_PLUGIN1)
TEST_PLUGIN1_COVERAGE_LIB = $(TEST_PLUGIN_COVERAGE_BUILD_DIR)/$(TEST_PLUGIN1)

TEST_PLUGIN2 = test_plugin2.so
TEST_PLUGIN2_DEBUG_LIB = $(TEST_PLUGIN_DEBUG_BUILD_DIR)/$(TEST_PLUGIN2)
TEST_PLUGIN2_RELEASE_LIB = $(TEST_PLUGIN_RELEASE_BUILD_DIR)/$(TEST_PLUGIN2)
TEST_PLUGIN2_COVERAGE_LIB = $(TEST_PLUGIN_COVERAGE_BUILD_DIR)/$(TEST_PLUGIN2)

TEST_PLUGIN3 = test_plugin3.so
TEST_PLUGIN3_DEBUG_LIB = $(TEST_PLUGIN_DEBUG_BUILD_DIR)/$(TEST_PLUGIN3)
TEST_PLUGIN3_RELEASE_LIB = $(TEST_PLUGIN_RELEASE_BUILD_DIR)/$(TEST_PLUGIN3)
TEST_PLUGIN3_COVERAGE_LIB = $(TEST_PLUGIN_COVERAGE_BUILD_DIR)/$(TEST_PLUGIN3)

TEST_PLUGIN4 = test_plugin4.so
TEST_PLUGIN4_DEBUG_LIB = $(TEST_PLUGIN_DEBUG_BUILD_DIR)/$(TEST_PLUGIN4)
TEST_PLUGIN4_RELEASE_LIB = $(TEST_PLUGIN_RELEASE_BUILD_DIR)/$(TEST_PLUGIN4)
TEST_PLUGIN4_COVERAGE_LIB = $(TEST_PLUGIN_COVERAGE_BUILD_DIR)/$(TEST_PLUGIN4)

TEST_PLUGIN5 = test_plugin5.so
TEST_PLUGIN5_DEBUG_LIB = $(TEST_PLUGIN_DEBUG_BUILD_DIR)/$(TEST_PLUGIN5)
TEST_PLUGIN5_RELEASE_LIB = $(TEST_PLUGIN_RELEASE_BUILD_DIR)/$(TEST_PLUGIN5)
TEST_PLUGIN5_COVERAGE_LIB = $(TEST_PLUGIN_COVERAGE_BUILD_DIR)/$(TEST_PLUGIN5)

TEST_PLUGIN6 = test_plugin6.so
TEST_PLUGIN6_DEBUG_LIB = $(TEST_PLUGIN_DEBUG_BUILD_DIR)/$(TEST_PLUGIN6)
TEST_PLUGIN6_RELEASE_LIB = $(TEST_PLUGIN_RELEASE_BUILD_DIR)/$(TEST_PLUGIN6)
TEST_PLUGIN6_COVERAGE_LIB = $(TEST_PLUGIN_COVERAGE_BUILD_DIR)/$(TEST_PLUGIN6)

TEST_PLUGIN7 = test_plugin7.so
TEST_PLUGIN7_DEBUG_LIB = $(TEST_PLUGIN_DEBUG_BUILD_DIR)/$(TEST_PLUGIN7)
TEST_PLUGIN7_RELEASE_LIB = $(TEST_PLUGIN_RELEASE_BUILD_DIR)/$(TEST_PLUGIN7)
TEST_PLUGIN7_COVERAGE_LIB = $(TEST_PLUGIN_COVERAGE_BUILD_DIR)/$(TEST_PLUGIN7)

TEST_PLUGIN8 = test_plugin8.so
TEST_PLUGIN8_DEBUG_LIB = $(TEST_PLUGIN_DEBUG_BUILD_DIR)/$(TEST_PLUGIN8)
TEST_PLUGIN8_RELEASE_LIB = $(TEST_PLUGIN_RELEASE_BUILD_DIR)/$(TEST_PLUGIN8)
TEST_PLUGIN8_COVERAGE_LIB = $(TEST_PLUGIN_COVERAGE_BUILD_DIR)/$(TEST_PLUGIN8)

TEST_PLUGIN9 = libtest_plugin9.so
TEST_PLUGIN9_DEBUG_LIB = $(TEST_PLUGIN_DEBUG_BUILD_DIR)/$(TEST_PLUGIN9)
TEST_PLUGIN9_RELEASE_LIB = $(TEST_PLUGIN_RELEASE_BUILD_DIR)/$(TEST_PLUGIN9)
TEST_PLUGIN9_COVERAGE_LIB = $(TEST_PLUGIN_COVERAGE_BUILD_DIR)/$(TEST_PLUGIN9)

TEST_PLUGIN1_DEBUG_OBJS = \
  $(TEST_PLUGIN1_SRC:%.c=$(TEST_PLUGIN_DEBUG_BUILD_DIR)/plugin_%.o)
TEST_PLUGIN1_RELEASE_OBJS = \
  $(TEST_PLUGIN1_SRC:%.c=$(TEST_PLUGIN_RELEASE_BUILD_DIR)/plugin_%.o)
TEST_PLUGIN1_COVERAGE_OBJS = \
  $(TEST_PLUGIN1_SRC:%.c=$(TEST_PLUGIN_COVERAGE_BUILD_DIR)/plugin_%.o)

TEST_PLUGIN2_DEBUG_OBJS = \
  $(TEST_PLUGIN2_SRC:%.c=$(TEST_PLUGIN_DEBUG_BUILD_DIR)/plugin_%.o)
TEST_PLUGIN2_RELEASE_OBJS = \
  $(TEST_PLUGIN2_SRC:%.c=$(TEST_PLUGIN_RELEASE_BUILD_DIR)/plugin_%.o)
TEST_PLUGIN2_COVERAGE_OBJS = \
  $(TEST_PLUGIN2_SRC:%.c=$(TEST_PLUGIN_COVERAGE_BUILD_DIR)/plugin_%.o)

TEST_PLUGIN3_DEBUG_OBJS = \
  $(TEST_PLUGIN3_SRC:%.c=$(TEST_PLUGIN_DEBUG_BUILD_DIR)/plugin_%.o)
TEST_PLUGIN3_RELEASE_OBJS = \
  $(TEST_PLUGIN3_SRC:%.c=$(TEST_PLUGIN_RELEASE_BUILD_DIR)/plugin_%.o)
TEST_PLUGIN3_COVERAGE_OBJS = \
  $(TEST_PLUGIN3_SRC:%.c=$(TEST_PLUGIN_COVERAGE_BUILD_DIR)/plugin_%.o)

TEST_PLUGIN4_DEBUG_OBJS = \
  $(TEST_PLUGIN4_SRC:%.c=$(TEST_PLUGIN_DEBUG_BUILD_DIR)/plugin_%.o)
TEST_PLUGIN4_RELEASE_OBJS = \
  $(TEST_PLUGIN4_SRC:%.c=$(TEST_PLUGIN_RELEASE_BUILD_DIR)/plugin_%.o)
TEST_PLUGIN4_COVERAGE_OBJS = \
  $(TEST_PLUGIN4_SRC:%.c=$(TEST_PLUGIN_COVERAGE_BUILD_DIR)/plugin_%.o)

TEST_PLUGIN5_DEBUG_OBJS = \
  $(TEST_PLUGIN5_SRC:%.c=$(TEST_PLUGIN_DEBUG_BUILD_DIR)/plugin_%.o)
TEST_PLUGIN5_RELEASE_OBJS = \
  $(TEST_PLUGIN5_SRC:%.c=$(TEST_PLUGIN_RELEASE_BUILD_DIR)/plugin_%.o)
TEST_PLUGIN5_COVERAGE_OBJS = \
  $(TEST_PLUGIN5_SRC:%.c=$(TEST_PLUGIN_COVERAGE_BUILD_DIR)/plugin_%.o)

TEST_PLUGIN6_DEBUG_OBJS = \
  $(TEST_PLUGIN6_SRC:%.c=$(TEST_PLUGIN_DEBUG_BUILD_DIR)/plugin_%.o)
TEST_PLUGIN6_RELEASE_OBJS = \
  $(TEST_PLUGIN6_SRC:%.c=$(TEST_PLUGIN_RELEASE_BUILD_DIR)/plugin_%.o)
TEST_PLUGIN6_COVERAGE_OBJS = \
  $(TEST_PLUGIN6_SRC:%.c=$(TEST_PLUGIN_COVERAGE_BUILD_DIR)/plugin_%.o)

TEST_PLUGIN7_DEBUG_OBJS = \
  $(TEST_PLUGIN7_SRC:%.c=$(TEST_PLUGIN_DEBUG_BUILD_DIR)/plugin_%.o)
TEST_PLUGIN7_RELEASE_OBJS = \
  $(TEST_PLUGIN7_SRC:%.c=$(TEST_PLUGIN_RELEASE_BUILD_DIR)/plugin_%.o)
TEST_PLUGIN7_COVERAGE_OBJS = \
  $(TEST_PLUGIN7_SRC:%.c=$(TEST_PLUGIN_COVERAGE_BUILD_DIR)/plugin_%.o)

# Duplicate plugin:
TEST_PLUGIN8_DEBUG_OBJS = $(TEST_PLUGIN2_DEBUG_OBJS)
TEST_PLUGIN8_RELEASE_OBJS = $(TEST_PLUGIN2_RELEASE_OBJS)
TEST_PLUGIN8_COVERAGE_OBJS = $(TEST_PLUGIN2_COVERAGE_OBJS)

# Ignored plugin:
TEST_PLUGIN9_DEBUG_OBJS = $(TEST_PLUGIN6_DEBUG_OBJS)
TEST_PLUGIN9_RELEASE_OBJS = $(TEST_PLUGIN6_RELEASE_OBJS)
TEST_PLUGIN9_COVERAGE_OBJS = $(TEST_PLUGIN6_COVERAGE_OBJS)

TEST_PLUGIN_DEBUG_OBJS = \
  $(TEST_PLUGIN1_DEBUG_OBJS) \
  $(TEST_PLUGIN2_DEBUG_OBJS) \
  $(TEST_PLUGIN3_DEBUG_OBJS) \
  $(TEST_PLUGIN4_DEBUG_OBJS) \
  $(TEST_PLUGIN5_DEBUG_OBJS) \
  $(TEST_PLUGIN6_DEBUG_OBJS) \
  $(TEST_PLUGIN7_DEBUG_OBJS)
TEST_PLUGIN_RELEASE_OBJS = \
  $(TEST_PLUGIN1_RELEASE_OBJS) \
  $(TEST_PLUGIN2_RELEASE_OBJS) \
  $(TEST_PLUGIN3_RELEASE_OBJS) \
  $(TEST_PLUGIN4_RELEASE_OBJS) \
  $(TEST_PLUGIN5_RELEASE_OBJS) \
  $(TEST_PLUGIN6_RELEASE_OBJS) \
  $(TEST_PLUGIN7_RELEASE_OBJS)
TEST_PLUGIN_COVERAGE_OBJS = \
  $(TEST_PLUGIN1_COVERAGE_OBJS) \
  $(TEST_PLUGIN2_COVERAGE_OBJS) \
  $(TEST_PLUGIN3_COVERAGE_OBJS) \
  $(TEST_PLUGIN4_COVERAGE_OBJS) \
  $(TEST_PLUGIN5_COVERAGE_OBJS) \
  $(TEST_PLUGIN6_COVERAGE_OBJS) \
  $(TEST_PLUGIN7_COVERAGE_OBJS)

$(TEST_PLUGIN_DEBUG_OBJS): | $(TEST_PLUGIN_DEBUG_BUILD_DIR)
$(TEST_PLUGIN_RELEASE_OBJS): | $(TEST_PLUGIN_RELEASE_BUILD_DIR)
$(TEST_PLUGIN_COVERAGE_OBJS): | $(TEST_PLUGIN_COVERAGE_BUILD_DIR)

TEST_PLUGIN_FLAGS = -fvisibility=hidden -DNFC_PLUGIN_EXTERNAL
EXTRA_EXE_LDFLAGS = -Wl,-export-dynamic

DEBUG_DEPS = \
  $(TEST_PLUGIN1_DEBUG_LIB) \
  $(TEST_PLUGIN2_DEBUG_LIB) \
  $(TEST_PLUGIN3_DEBUG_LIB) \
  $(TEST_PLUGIN4_DEBUG_LIB) \
  $(TEST_PLUGIN5_DEBUG_LIB) \
  $(TEST_PLUGIN6_DEBUG_LIB) \
  $(TEST_PLUGIN7_DEBUG_LIB) \
  $(TEST_PLUGIN8_DEBUG_LIB) \
  $(TEST_PLUGIN9_DEBUG_LIB)
RELEASE_DEPS = \
  $(TEST_PLUGIN1_RELEASE_LIB) \
  $(TEST_PLUGIN2_RELEASE_LIB) \
  $(TEST_PLUGIN3_RELEASE_LIB) \
  $(TEST_PLUGIN4_RELEASE_LIB) \
  $(TEST_PLUGIN5_RELEASE_LIB) \
  $(TEST_PLUGIN6_RELEASE_LIB) \
  $(TEST_PLUGIN7_RELEASE_LIB) \
  $(TEST_PLUGIN8_RELEASE_LIB) \
  $(TEST_PLUGIN9_RELEASE_LIB)
COVERAGE_DEPS = \
  $(TEST_PLUGIN1_COVERAGE_LIB) \
  $(TEST_PLUGIN2_COVERAGE_LIB) \
  $(TEST_PLUGIN3_COVERAGE_LIB) \
  $(TEST_PLUGIN4_COVERAGE_LIB) \
  $(TEST_PLUGIN5_COVERAGE_LIB) \
  $(TEST_PLUGIN6_COVERAGE_LIB) \
  $(TEST_PLUGIN7_COVERAGE_LIB) \
  $(TEST_PLUGIN8_COVERAGE_LIB) \
  $(TEST_PLUGIN9_COVERAGE_LIB)

DEPS = \
  $(TEST_PLUGIN_DEBUG_OBJS:%.o=%.d) \
  $(TEST_PLUGIN_RELEASE_OBJS:%.o=%.d) \
  $(TEST_PLUGIN_COVERAGE_OBJS:%.o=%.d)

include ../common/Makefile

$(DEBUG_BUILD_DIR)/plugin_%.o : $(TEST_PLUGIN_SRC_DIR)/%.c
	$(CC) -c $(DEBUG_CFLAGS) $(TEST_PLUGIN_FLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@

$(RELEASE_BUILD_DIR)/plugin_%.o : $(TEST_PLUGIN_SRC_DIR)/%.c
	$(CC) -c $(RELEASE_CFLAGS) $(TEST_PLUGIN_FLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@

$(COVERAGE_BUILD_DIR)/plugin_%.o : $(TEST_PLUGIN_SRC_DIR)/%.c
	$(CC) -c $(COVERAGE_CFLAGS) $(TEST_PLUGIN_FLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@

$(TEST_PLUGIN1_DEBUG_LIB): $(TEST_PLUGIN1_DEBUG_OBJS)
	$(LD) -shared $^ $(DEBUG_LDFLAGS) $(LIBS) -o $@

$(TEST_PLUGIN1_RELEASE_LIB): $(TEST_PLUGIN1_RELEASE_OBJS)
	$(LD) -shared $^ $(RELEASE_LDFLAGS) $(LIBS) -o $@

$(TEST_PLUGIN1_COVERAGE_LIB): $(TEST_PLUGIN1_COVERAGE_OBJS)
	$(LD) -shared $^ $(COVERAGE_LDFLAGS) $(LIBS) -o $@

$(TEST_PLUGIN2_DEBUG_LIB): $(TEST_PLUGIN2_DEBUG_OBJS)
	$(LD) -shared $^ $(DEBUG_LDFLAGS) $(LIBS) -o $@

$(TEST_PLUGIN2_RELEASE_LIB): $(TEST_PLUGIN2_RELEASE_OBJS)
	$(LD) -shared $^ $(RELEASE_LDFLAGS) $(LIBS) -o $@

$(TEST_PLUGIN2_COVERAGE_LIB): $(TEST_PLUGIN2_COVERAGE_OBJS)
	$(LD) -shared $^ $(COVERAGE_LDFLAGS) $(LIBS) -o $@

$(TEST_PLUGIN3_DEBUG_LIB): $(TEST_PLUGIN3_DEBUG_OBJS)
	$(LD) -shared $^ $(DEBUG_LDFLAGS) $(LIBS) -o $@

$(TEST_PLUGIN3_RELEASE_LIB): $(TEST_PLUGIN3_RELEASE_OBJS)
	$(LD) -shared $^ $(RELEASE_LDFLAGS) $(LIBS) -o $@

$(TEST_PLUGIN3_COVERAGE_LIB): $(TEST_PLUGIN3_COVERAGE_OBJS)
	$(LD) -shared $^ $(COVERAGE_LDFLAGS) $(LIBS) -o $@

$(TEST_PLUGIN4_DEBUG_LIB): $(TEST_PLUGIN4_DEBUG_OBJS)
	$(LD) -shared $^ $(DEBUG_LDFLAGS) $(LIBS) -o $@

$(TEST_PLUGIN4_RELEASE_LIB): $(TEST_PLUGIN4_RELEASE_OBJS)
	$(LD) -shared $^ $(RELEASE_LDFLAGS) $(LIBS) -o $@

$(TEST_PLUGIN4_COVERAGE_LIB): $(TEST_PLUGIN4_COVERAGE_OBJS)
	$(LD) -shared $^ $(COVERAGE_LDFLAGS) $(LIBS) -o $@

$(TEST_PLUGIN5_DEBUG_LIB): $(TEST_PLUGIN5_DEBUG_OBJS)
	$(LD) -shared $^ $(DEBUG_LDFLAGS) $(LIBS) -o $@

$(TEST_PLUGIN5_RELEASE_LIB): $(TEST_PLUGIN5_RELEASE_OBJS)
	$(LD) -shared $^ $(RELEASE_LDFLAGS) $(LIBS) -o $@

$(TEST_PLUGIN5_COVERAGE_LIB): $(TEST_PLUGIN5_COVERAGE_OBJS)
	$(LD) -shared $^ $(COVERAGE_LDFLAGS) $(LIBS) -o $@

$(TEST_PLUGIN6_DEBUG_LIB): $(TEST_PLUGIN6_DEBUG_OBJS)
	$(LD) -shared $^ $(DEBUG_LDFLAGS) $(LIBS) -o $@

$(TEST_PLUGIN6_RELEASE_LIB): $(TEST_PLUGIN6_RELEASE_OBJS)
	$(LD) -shared $^ $(RELEASE_LDFLAGS) $(LIBS) -o $@

$(TEST_PLUGIN6_COVERAGE_LIB): $(TEST_PLUGIN6_COVERAGE_OBJS)
	$(LD) -shared $^ $(COVERAGE_LDFLAGS) $(LIBS) -o $@

$(TEST_PLUGIN7_DEBUG_LIB): $(TEST_PLUGIN7_DEBUG_OBJS)
	$(LD) -shared $^ $(DEBUG_LDFLAGS) $(LIBS) -o $@

$(TEST_PLUGIN7_RELEASE_LIB): $(TEST_PLUGIN7_RELEASE_OBJS)
	$(LD) -shared $^ $(RELEASE_LDFLAGS) $(LIBS) -o $@

$(TEST_PLUGIN7_COVERAGE_LIB): $(TEST_PLUGIN7_COVERAGE_OBJS)
	$(LD) -shared $^ $(COVERAGE_LDFLAGS) $(LIBS) -o $@

$(TEST_PLUGIN8_DEBUG_LIB): $(TEST_PLUGIN8_DEBUG_OBJS)
	$(LD) -shared $^ $(DEBUG_LDFLAGS) $(LIBS) -o $@

$(TEST_PLUGIN8_RELEASE_LIB): $(TEST_PLUGIN8_RELEASE_OBJS)
	$(LD) -shared $^ $(RELEASE_LDFLAGS) $(LIBS) -o $@

$(TEST_PLUGIN8_COVERAGE_LIB): $(TEST_PLUGIN8_COVERAGE_OBJS)
	$(LD) -shared $^ $(COVERAGE_LDFLAGS) $(LIBS) -o $@

$(TEST_PLUGIN9_DEBUG_LIB): $(TEST_PLUGIN8_DEBUG_OBJS)
	$(LD) -shared $^ $(DEBUG_LDFLAGS) $(LIBS) -o $@

$(TEST_PLUGIN9_RELEASE_LIB): $(TEST_PLUGIN8_RELEASE_OBJS)
	$(LD) -shared $^ $(RELEASE_LDFLAGS) $(LIBS) -o $@

$(TEST_PLUGIN9_COVERAGE_LIB): $(TEST_PLUGIN8_COVERAGE_OBJS)
	$(LD) -shared $^ $(COVERAGE_LDFLAGS) $(LIBS) -o $@
